package com.aistar.user.service.impl;

import com.aistar.user.entity.User;
import com.aistar.user.mapper.UserMapper;
import com.aistar.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;



/**
 * Created by js on 2019/6/23.
 */
@Service
@Transactional
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper mapper;

    @Autowired
    private RedisTemplate redisTemplate;



    @Override
    public void save(User user) {
        mapper.save(user);
    }

    @Override
    public User findById(String id) {

//        User user= (User) redisTemplate.opsForValue().get("user_"+id);
//        if (null==user){
//            user=mapper.findById(id);
//            redisTemplate.opsForValue().set("user_"+id,user);
//        }
        return mapper.findById(id);
    }

    @Override
    public User findByUsername(String username) {
        return mapper.findByUsername(username);
    }

    @Override
    public User findByPhone(String phone) {
        return mapper.findByPhone(phone);
    }

    @Override
    public User findByEmail(String email) {
        return mapper.findByEmail(email);
    }

    @Override
    public void update(User user) {
        mapper.update(user);
    }

    @Override
    public User findUser(User user) {


        return mapper.findUser(user);
    }

    @Override
    public void updatePassword(User user) {
        mapper.updatePassword(user);
    }


}
